package com.yy.job.console.utils;

import java.text.MessageFormat;

public enum CommonErrorCode {
	
	SUCCESS("0", "success"),
	FAIL("20001", "操作失败, 原因={0}");
	
	;
	
	private String code;
	private String pattern;

	CommonErrorCode(String code, String pattern) {
		this.code = code;
		this.pattern = pattern;
	}

	public String getCode() {
		return this.code;
	}
	
	public String getErrorMsg() {
		return this.getErrorMsg(new Object[0]);
	}
	
	public String getErrorMsg(Object... params) {
		String errorMsg = null;
		if (params == null || params.length == 0) {
			errorMsg = this.pattern;
		} else {
			MessageFormat msgFmt = new MessageFormat(this.pattern);
			errorMsg = msgFmt.format(params);
		}
		return errorMsg;
	}

	public String getErrorMsg(String... params) {
		String errorMsg = null;
		if (params == null || params.length == 0) {
			errorMsg = this.pattern;
		} else {
			MessageFormat msgFmt = new MessageFormat(this.pattern);
			errorMsg = msgFmt.format(params);
		}
		return errorMsg;
	}
	
}
